import { reactive, computed, onBeforeMount, inject } from 'vue'
import { indexApi } from '@/api'
export default () => {
    const indicatorColor = inject('themeColor')
    const swipes = reactive([])
    const hasSwipes = computed(() => swipes.length > 0)

    // 获取轮播图数据
    const getSwipes = async () => {
        try {
            const { data } = await indexApi.getSwipe()
            if (Array.isArray(data)) {
                swipes.push(...data)
            }
        } catch (error) {
            console.log(error)
        }
    }

    onBeforeMount(() => {
        getSwipes()
    })

    return {
        swipes,
        hasSwipes,
        indicatorColor
    }
}